const http = require('http')
const Koa = require('koa')
const logger = require('koa-logger')
const json = require('koa-json')
const moment = require('moment')

const router = require('./router')

const app = new Koa()
app.use(
  logger((str) => {
    console.log(moment().format('YYYY-MM-DD HH:mm:ss') + str)
  })
)
app.use(json())
app.use(router.routes(), router.allowedMethods())

const server = http.createServer(app.callback())
app.listen(5000, () => {
  console.log('server is running at http://localhost:5000')
})
